import React from 'react';
import { inject, observer} from 'mobx-react';
import loadjs from 'loadjs';
import { workflowPublicFiles } from '../constants/fileConfig';
import Loading from './Loading';
import allStore from '../stores';
import isEmpty from 'lodash/isEmpty';

@observer
export default class ModifyLog extends React.Component{
    constructor(){
        super();
        this.state = {
            hasLoad: false,
            store: null
        };
    }
    componentDidMount(){
        const init = () =>{
            const { WfFormModifyLogStore } = window.weaWorkflowPublic;
            const store = new WfFormModifyLogStore();
            this.setState({hasLoad:true, store:store});
        }
        loadjs.isDefined('workflowPublic') ? loadjs.ready('workflowPublic', init) : loadjs(workflowPublicFiles, 'workflowPublic', init);
    }
    componentWillUnmount(){
        allStore.wfGlobalStore.controlModifyLogParams({});
    }
    render(){
        const { hasLoad,store } = this.state;
        if(hasLoad){
            const { WfFormModifyLogCom } = window.weaWorkflowPublic;
            let modifyLogParams = mobx.toJS(allStore.wfGlobalStore.modifyLogParams);
            if(!isEmpty(modifyLogParams))
                store.appendBaseParams(modifyLogParams, true);
            return (
                <WfFormModifyLogCom ecId={`${this && this.props && this.props.ecId || ''}_WfFormModifyLogCom@7q4ji4`} wfFormModifyLogStore={store} />
            )
        }else{
            return (<Loading ecId={`${this && this.props && this.props.ecId || ''}_Loading@4yebv5`} />);
        }
    }
}